
<UserControl x:Class="RibbonWindowSample.UserControlMvvm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:RibbonWindowSample"
    xmlns:data="clr-namespace:RibbonWindowSample.ViewModel"
    Loaded="UserControl_Loaded"
    Unloaded="UserControl_Unloaded">
    <Grid x:Name="MainGrid">
        <Grid.Resources>
            <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
            <!-- RibbonTab -->
            <Style TargetType="{x:Type ribbon:RibbonTab}">
                <Setter Property="ContextualTabGroupHeader" Value="{Binding ContextualTabGroupHeader}" />
                <Setter Property="Header" Value="{Binding Header}" />
                <Setter Property="ItemsSource" Value="{Binding GroupDataCollection}" />
            </Style>
            <!-- RibbonContextualTabGroup -->
            <Style TargetType="{x:Type ribbon:RibbonContextualTabGroup}">
                <Setter Property="Header" Value="{Binding Header}" />
                <Setter Property="Visibility" Value="{Binding IsVisible,Converter={StaticResource BoolToVisibilityConverter}}" />
            </Style>
            <!-- RibbonControl -->
            <Style x:Key="RibbonControlStyle">
                <Setter Property="ribbon:RibbonControlService.Label" Value="{Binding Label}" />
                <Setter Property="ribbon:RibbonControlService.LargeImageSource" Value="{Binding LargeImage}" />
                <Setter Property="ribbon:RibbonControlService.SmallImageSource" Value="{Binding SmallImage}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipTitle" Value="{Binding ToolTipTitle}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipDescription" Value="{Binding ToolTipDescription}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipImageSource" Value="{Binding ToolTipImage}" />
            </Style>
            <!-- RibbonGroup -->
            <Style TargetType="{x:Type ribbon:RibbonGroup}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="QuickAccessToolBarId" Value="{Binding Label}" />
                <Setter Property="Header" Value="{Binding Label}" />
                <Setter Property="ItemsSource" Value="{Binding ControlDataCollection}" />
            </Style>
            <!-- RibbonButton -->
            <DataTemplate DataType="{x:Type data:ButtonData}">
                <ribbon:RibbonButton />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonButton}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="Command" Value="{Binding Command}" />
            </Style>
            <!-- RibbonToggleButton -->
            <DataTemplate DataType="{x:Type data:ToggleButtonData}">
                <ribbon:RibbonToggleButton />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonToggleButton}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="IsChecked" Value="{Binding IsChecked}" />
            </Style>
            <!-- RibbonRadioButton -->
            <DataTemplate DataType="{x:Type data:RadioButtonData}">
                <ribbon:RibbonRadioButton />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonRadioButton}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="IsChecked" Value="{Binding IsChecked}" />
            </Style>
            <!-- RibbonCheckBox -->
            <DataTemplate DataType="{x:Type data:CheckBoxData}">
                <ribbon:RibbonCheckBox />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonCheckBox}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="IsChecked" Value="{Binding IsChecked}" />
            </Style>
            <!-- RibbonTextBox -->
            <DataTemplate DataType="{x:Type data:TextBoxData}">
                <ribbon:RibbonTextBox />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonTextBox}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="Text" Value="{Binding Text}" />
            </Style>
            <!-- RibbonMenuButton -->
            <DataTemplate DataType="{x:Type data:MenuButtonData}">
                <ribbon:RibbonMenuButton />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonMenuButton}" BasedOn="{StaticResource RibbonControlStyle}">
                <Setter Property="ItemsSource" Value="{Binding ControlDataCollection}" />
                <Setter Property="QuickAccessToolBarId" Value="{Binding Command}" />
                <Setter Property="CanUserResizeHorizontally" Value="True" />
                <Setter Property="CanUserResizeVertically" Value="True" />
                <Setter Property="UsesItemContainerTemplate" Value="True" />
                <Setter Property="DropDownHeight" Value="200" />
            </Style>
            <!-- RibbonSplitButton -->
            <DataTemplate DataType="{x:Type data:SplitButtonData}">
                <ribbon:RibbonSplitButton />
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonSplitButton}" BasedOn="{StaticResource {x:Type ribbon:RibbonMenuButton}}">
                <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
                <Setter Property="IsChecked" Value="{Binding IsChecked}" />
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="HeaderQuickAccessToolBarId" Value="{Binding Label}" />
                <Setter Property="CanUserResizeHorizontally" Value="True" />
                <Setter Property="CanUserResizeVertically" Value="True" />
                <Setter Property="UsesItemContainerTemplate" Value="True" />
                <Setter Property="DropDownHeight" Value="200" />
            </Style>
            <!-- RibbonComboBox -->
            <DataTemplate DataType="{x:Type data:ComboBoxData}">
                <ribbon:RibbonComboBox
                    IsEditable="True"
                    TextSearch.TextPath="Label"/>
            </DataTemplate>
            <Style TargetType="{x:Type ribbon:RibbonComboBox}" BasedOn="{StaticResource {x:Type ribbon:RibbonMenuButton}}">
                <Setter Property="IsEditable" Value="True" />
                <Setter Property="TextSearch.TextPath" Value="Label" />
            </Style>
            <!-- RibbonGallery -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:GalleryData}}">

                <ribbon:RibbonGallery />



            </DataTemplate>

            <Style TargetType="{x:Type ribbon:RibbonGallery}">
                <Style.Resources>
                    <!-- Note that this Style has been specified only to trump the 
                         implicit style for RibbonMenuItem from being picked by the 
                         items within the FilterMenuButton -->
                    <Style TargetType="{x:Type ribbon:RibbonMenuItem}" />
                    <DataTemplate x:Key="FilterItemTemplate">
                        <TextBlock Text="{Binding Label}" />
                    </DataTemplate>
                </Style.Resources>
                <Setter Property="ribbon:RibbonControlService.SmallImageSource" Value="{Binding SmallImage}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipTitle" Value="{Binding ToolTipTitle}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipDescription" Value="{Binding ToolTipDescription}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipImageSource" Value="{Binding ToolTipImage}" />
                <Setter Property="ItemsSource" Value="{Binding CategoryDataCollection}" />
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="SelectedItem" Value="{Binding SelectedItem}" />
                <Setter Property="MinColumnCount" Value="3" />
                <Setter Property="CanUserFilter" Value="True" />
                <Setter Property="FilterItemTemplate" Value="{StaticResource FilterItemTemplate}" />
            </Style>
            <!-- RibbonGalleryCategory -->
            <Style TargetType="{x:Type ribbon:RibbonGalleryCategory}">
                <Setter Property="Header" Value="{Binding Label}" />
                <Setter Property="ItemsSource" Value="{Binding GalleryItemDataCollection}" />
            </Style>
            <!-- RibbonGalleryItem -->
            <DataTemplate DataType="{x:Type data:GalleryItemData}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Image Source="{Binding LargeImage}" Height="32" Width="32" />
                    <TextBlock Grid.Row="1" Text="{Binding Label}" />
                </Grid>
            </DataTemplate>
            <!-- RibbonMenuItem -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:MenuItemData}}">

                <ribbon:RibbonMenuItem />



            </DataTemplate>

            <Style TargetType="{x:Type ribbon:RibbonMenuItem}">
                <Setter Property="ImageSource" Value="{Binding SmallImage}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipTitle" Value="{Binding ToolTipTitle}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipDescription" Value="{Binding ToolTipDescription}" />
                <Setter Property="ribbon:RibbonControlService.ToolTipImageSource" Value="{Binding ToolTipImage}" />
                <Setter Property="Command" Value="{Binding Command}" />
                <Setter Property="CanUserResizeHorizontally" Value="True" />
                <Setter Property="CanUserResizeVertically" Value="True" />
                <Setter Property="UsesItemContainerTemplate" Value="True" />
                <Setter Property="DropDownHeight" Value="200" />
                <Setter Property="ItemsSource" Value="{Binding ControlDataCollection}" />
                <Setter Property="IsCheckable" Value="{Binding IsCheckable}" />
                <Setter Property="IsChecked" Value="{Binding IsChecked}" />
                <!-- Note that setting Header property is not sufficient in this case 
                     because the HeaderTemplate is implicitly resolved to type MenuItemData 
                     which is the item for this container. Hence we explicitly specify the 
                     HeaderTemplate to avoid the implicit DataTemplate resolution from kicking in. -->
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <TextBlock Text="{Binding Label}" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <!-- RibbonSplitMenuItem -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:SplitMenuItemData}}">

                <ribbon:RibbonSplitMenuItem />



            </DataTemplate>

            <Style TargetType="{x:Type ribbon:RibbonSplitMenuItem}" BasedOn="{StaticResource {x:Type ribbon:RibbonMenuItem}}">
                <Setter Property="HeaderQuickAccessToolBarId" Value="{Binding Label}" />
                <Style.Triggers>
                    <Trigger Property="HasItems" Value="false">
                        <Setter Property="HeaderQuickAccessToolBarId" Value="{x:Null}" />
                    </Trigger>
                </Style.Triggers>
            </Style>
            <!-- RibbonSeparator -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:SeparatorData}}">

                <ribbon:RibbonSeparator />



            </DataTemplate>

            <!-- RibbonApplicationMenuItem -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:ApplicationMenuItemData}}">

                <ribbon:RibbonApplicationMenuItem />



            </DataTemplate>

            <Style TargetType="{x:Type ribbon:RibbonApplicationMenuItem}" BasedOn="{StaticResource {x:Type ribbon:RibbonMenuItem}}" />
            <!-- RibbonApplicationSplitMenuItem -->



            <!-- This should have been ItemContainerTemplate. The only reason it 
                 isn't is due to a limitation in .NET 3.5 that we aren't able to parse 
                 custom template types. This is fixed for the .NET 4.0+ Ribbon. -->
            <DataTemplate x:Key="{ItemContainerTemplateKey DataType={x:Type data:ApplicationSplitMenuItemData}}">

                <ribbon:RibbonApplicationSplitMenuItem />



            </DataTemplate>

            <Style TargetType="{x:Type ribbon:RibbonApplicationSplitMenuItem}" BasedOn="{StaticResource {x:Type ribbon:RibbonSplitMenuItem}}" />
            <!-- RibbonContextMenu -->
            <Style TargetType="{x:Type ribbon:RibbonContextMenu}">
                <Style.Resources>
                    <!-- Note that this Style has been specified only to trump the 
                         implicit style for RibbonMenuItem from being picked by the 
                         items within the ContextMenu -->
                    <Style TargetType="{x:Type ribbon:RibbonMenuItem}" />
                </Style.Resources>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ribbon:Ribbon x:Name="ribbon"
            Grid.Row="0"
            ItemsSource="{Binding Source={x:Static data:ViewModelData.RibbonData},Path=TabDataCollection}"
            ContextualTabGroupsSource="{Binding Source={x:Static data:ViewModelData.RibbonData},Path=ContextualTabGroupDataCollection}">
            <ribbon:Ribbon.ApplicationMenu>
                <ribbon:RibbonApplicationMenu 
                    DataContext="{Binding Source={x:Static data:ViewModelData.RibbonData},Path=ApplicationMenuData}" 
                    SmallImageSource="{Binding SmallImage}"
                    ToolTipTitle="{Binding ToolTipTitle}"
                    ToolTipDescription="{Binding ToolTipDescription}"
                    ToolTipImageSource="{Binding ToolTipImage}"
                    UsesItemContainerTemplate="True"
                    ItemsSource="{Binding ControlDataCollection}" />
            </ribbon:Ribbon.ApplicationMenu>
        </ribbon:Ribbon>
        <RichTextBox Grid.Row="1" x:Name="RTB">
















            <FlowDocument>
                <Paragraph>
                    <Run>Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'</Run>
                </Paragraph>
                <Paragraph>
                    <Run>So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.</Run>
                </Paragraph>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</UserControl>
